home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH3 / animshape.cs < prev    next >
Text File  |  2006-06-28  |  3KB  |  77 lines

  1. // ========================================================================
  2. //  animshape.cs
  3. //
  4. //  This module contains the definition of a test shape, which uses
  5. //  a model of a stylized 3D logo. It also contains functions for placing
  6. //  the test shape in the game world and then animating the shape using
  7. //  a recurring scheduled function call.
  8. // ========================================================================
  9.  
  10.  
  11. function AnimShape(%shape, %dist, %angle, %scale)
  12. // ----------------------------------------------------
  13. //     moves the %shape by %dist amount, and then
  14. //     schedules itself to be called again in 1/5
  15. //     of a second.
  16. // ----------------------------------------------------
  17. {
  18.   echo("AnimShape: shape:", %shape, " dist:", 
  19.          %dist, " angle:", %angle, " scale:", %scale); 
  20.   if ( %shape $= "" || 
  21.        %dist  $= "" ||
  22.        %angle $= "" || 
  23.        %scale $= "" )
  24.   {
  25.    error("AnimShape needs 4 parameters.syntax:");
  26.    error("AnimShape(id,moveDist,turnAng,scaleVal);");
  27.    return;
  28.   }
  29.   %xfrm = %shape.getTransform();
  30.   %lx = getword(%xfrm,0); // first, get the current 
  31.   %ly = getword(%xfrm,1);         // transform values
  32.   %lz = getword(%xfrm,2);
  33.   %rx = getword(%xfrm,3);
  34.   %ry = getword(%xfrm,4);
  35.   %rz = getword(%xfrm,5);
  36.   %lx += %dist;           // set the new x position
  37.   %angle += 1.0;
  38.   %rd = %angle;           // Set the rotation angle
  39.   
  40.   if ($grow)        // if the shape is growing larger
  41.   {
  42.     if (%scale < 5.0)   // and hasn't gotten too big
  43.       %scale += 0.3;   // make it bigger
  44.     else
  45.       $grow = false; // if it's too big, then 
  46.   }                    // don't let it grow more
  47.   else                 // if it's shrinking
  48.   {
  49.     if (%scale > 3.0)  // and isn't too small
  50.       %scale -= 0.3;   // then make it smaller
  51.     else
  52.       $grow = true;   // if it's too small, 
  53.   }                  // don't let it grow smaller
  54.  
  55.  %shape.setScale(%scale SPC %scale SPC %scale);
  56.  %shape.setTransform(%lx SPC %ly SPC %lz SPC 
  57.                      %rx SPC %ry SPC %rz SPC %rd);
  58.  schedule(200,0,AnimShape, %shape, %dist, %angle, %scale);
  59. }
  60.  
  61. function DoAnimTest(%shape)
  62. // ----------------------------------------------------
  63. //     a function to tie together the instantion
  64. //     and the movement in one easy to type function
  65. //     call.
  66. // ----------------------------------------------------
  67. {
  68.   if (%shape $= "" && isObject(%shape))
  69.   {
  70.     error("DoAnimTest requires 1 parameter.");
  71.     error("DoAnimTest syntax: DoAnimTest(shapeID);");
  72.     return;
  73.   }
  74.   $grow = true;
  75.   AnimShape(%shape, 0.2, 1, 2);
  76. }
  77.